package com.yc.controller;

import com.yc.entity.AttendanceRecords;
import com.yc.service.AttendanceRecordsService;
import com.yc.service.impl.AttendanceRecordsServiceImpl;
import com.yc.vo.AttendanceHistory;
import com.yc.vo.Result;
import com.yc.vo.StudentAttendanceRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2023/7/17 14:08
 */
@Api("学生考勤记录控制器")
@RestController
@RequestMapping("/records")
public class AttendanceRecordsController {

    @Resource
    private AttendanceRecordsService attendanceRecordsService;



    @ApiOperation("查询学生当天的考勤详情信息")
    @GetMapping("/get/{stuid}")
    public Result selectAttendanceByStuidAndDate(@ApiParam(name = "stuid", value = "当前查询学生的学号", required = true)
                                                 @PathVariable("stuid") String stuid,
                                                 @RequestParam String date){

        Map<String, List<StudentAttendanceRecord>> studentAttendanceRecords = attendanceRecordsService.selectAttendanceByStuidAndDate(stuid, date);
        return Result.success(studentAttendanceRecords);
    }

    @ApiOperation("统计学生当年的考勤信息")
    @GetMapping("/get/all/{stuid}")
    public Result selectAllAttendanceByStudent(@ApiParam(name = "stuid", value = "当前查询学生的学号", required = true)
                                                   @PathVariable("stuid") String stuid,
                                               @RequestParam Integer date) {
        List<String> dates = attendanceRecordsService.selectNowSchoolYear(date);
        Map<String, Object> records = attendanceRecordsService.selectAllAttendanceByStudent(stuid, dates.get(0), dates.get(1));
        //Map<String, Object> records = attendanceRecordsService.selectAllAttendanceByStudent(stuid, "2023-07-01", "2024-07-01");
        return Result.success(records);
    }

    @ApiOperation("查询学生当月的考勤信息")
    @GetMapping("/get/month/{stuid}")
    public Result selectMonthStatusByStuidAndDate(@ApiParam(name = "stuid", value = "当前查询学生的学号", required = true)
                                                  @PathVariable("stuid") String stuid,
                                                  @RequestParam String date) {
        Map<String, List<StudentAttendanceRecord>> studentAttendanceRecords = attendanceRecordsService.selectMonthStatusByStuidAndDate(stuid, date);
        return Result.success(studentAttendanceRecords);
    }

    /**
     * @Description 查询指定班级的所有考勤信息
     * @Return
     * @Author dm
     * @Date Created in 2023/7/26 19:34
     **/
    @ApiOperation("查询班级的历史考勤信息")
    @GetMapping("/searchHistory")
    public Result queryHistory(AttendanceHistory attendanceHistory,
                               @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                               @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        return attendanceRecordsService.queryHistory(attendanceHistory, pageNum, pageSize);
    }
    @ApiOperation("手动添加学生考勤信息")
    @PostMapping("/add/{username}")
    public Result addAttendanceRecords(@ApiParam(name = "username", value = "老师工号", required = true)
                                       @PathVariable("username") String username,
                                       @RequestBody List<AttendanceRecords> attendanceRecords){
        if (attendanceRecords.size() > 0){
            attendanceRecordsService.addAttendanceRecords(attendanceRecords, username);
            return Result.success("考勤成功!");
        }
        return Result.error("暂无修改");
    }

    @ApiOperation("手动修改学生考勤信息")
    @PutMapping("/modify/{username}")
    public Result modifyAttendanceRecords(@ApiParam(name = "username", value = "老师工号", required = true)
                                          @PathVariable("username") String username,
                                          @RequestBody List<AttendanceRecords> attendanceRecords){
        if (attendanceRecords.size() > 0){
            attendanceRecordsService.modifyAttendanceRecords(attendanceRecords, username);
            return Result.success("考勤成功!");
        }
        return Result.error("暂无修改");
    }

}
